package cn.yitun.chat.yitunserverimcore.general.main.biz.group.manager;

import cn.yitun.chat.yitunservercommonlib.dataentity.dto.group.GroupRelationDto;
import cn.yitun.chat.yitunservercommonlib.dataentity.vo.group.GroupRelationVo;
import cn.yitun.chat.yitunserverimbase.dao.group.GroupRelationDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 
 * Date 2019-01-26 19:32:58<br>
 * Description
 * 
 * @author yitun<br>
 * @version 1.1
 */
@Service
public class GroupRelationManager {

	@Resource
	private GroupRelationDao groupRelationDAO;

	/**
	 * 
	 * Date 2019-01-26 19:34:27<br>
	 * Description
	 * 
	 * @author yitun<br>
	 * @param groupId
	 * @param userId
	 * @param categoryId
	 * @param remark
	 * @return
	 * @version 1.1
	 */
	public GroupRelationDto add(
			Long groupId,
			Long userId,
			Long categoryId,
			String remark) {
		GroupRelationDto bean = new GroupRelationDto();
		bean.setGroupId(groupId);
		bean.setUserId(userId);
		bean.setCategoryId(categoryId);
		bean.setRemark(remark);
		bean.setCreateBy(userId);
		bean.setUpdateBy(userId);
		groupRelationDAO.save(bean);
		return bean;
	}

	public boolean has(Long userId, Long groupId) {
		GroupRelationVo bean = groupRelationDAO.getVOByGroupId(userId, groupId);
		return bean != null;
	}
}
